package sseGameApps.controller.mdkbr.main;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.slim3.controller.Navigation;

import sseGameApps.controller.JsonController;
import sseGameApps.model.mdkbr.MdKbrUser;
import sseGameApps.service.mdkbr.MdKbrUserService;

public class MdRecordRankingController extends JsonController {

    private MdKbrUserService serviceMdKbrUser = new MdKbrUserService();

    @Override
    public Navigation run() throws Exception {

        List<MdKbrUser> mdKbrUserWinBest10 =
            serviceMdKbrUser.getMdKbrUserWinBest10();

        Map<String, String> data = new HashMap<String, String>();
        Integer cnt = 1;

        data.put("idCanvas", asString("idCanvas"));

        if (mdKbrUserWinBest10 == null) {
            data.put("userId", "");
        } else {
            data.put("userId", asString("userId"));

            for (MdKbrUser mdKbrUser : mdKbrUserWinBest10) {
                data.put("no" + cnt.toString() + "Name", mdKbrUser.getPlayerName());
                data.put("no" + cnt.toString() + "BTCnt", mdKbrUser.getBattleCount().toString());
                data.put("no" + cnt.toString() + "WinCnt", mdKbrUser.getWinCount().toString());
                data.put("no" + cnt.toString() + "LoseCnt", mdKbrUser.getLoseCount().toString());
                cnt++;
            }
        }

        this.toJson(data);

        return null;
    }
}
